package v1

import (
	"gitee.com/liangziyisheng/caas-platform-mc/internal/model/do"

	"gitee.com/liangziyisheng/caas-platform-mc/internal/model/entity"

	"github.com/gogf/gf/v2/frame/g"
)

type ListReq struct {
	g.Meta  `path:"/roles" tags:"角色管理" method:"get" summary:"角色列表"`
	AppCode string `json:"appCode" v:"required" description:"应用编码"`
}
type ListRes struct {
	g.Meta `mime:"application/json"`
	Data   []Role `json:"data"`
}

type Role struct {
	Id          int64  `json:"id" description:"角色ID"`
	AppCode     string `json:"appCode"`
	Name        string `json:"name" description:"角色名称"`
	Description string `json:"description" description:"角色描述"`
}

type AddReq struct {
	g.Meta      `path:"/roles" tags:"角色管理" method:"post" summary:"添加角色"`
	AppCode     string `json:"appCode" v:"required"`
	Name        string `json:"name" v:"required" description:"角色名称"`
	Description string `json:"description" description:"角色描述"`
}
type AddRes struct {
	g.Meta `mime:"application/json"`
	Id     int64 `json:"id"`
}

type UpdateReq struct {
	g.Meta      `path:"/roles/{id}" tags:"角色管理" method:"put" summary:"更新角色"`
	Id          int64  `query:"id" v:"required|min:1"`
	Description string `json:"description"`
}
type UpdateRes struct {
	g.Meta `mime:"application/json"`
	Rows   int64 `json:"rows"`
}

type DeleteReq struct {
	g.Meta `path:"/roles/{id}" tags:"角色管理" method:"delete" summary:"删除角色"`
	Id     int64 `query:"id" v:"required|min:1"`
}
type DeleteRes struct {
	g.Meta `mime:"application/json"`
	Rows   int64 `json:"rows"`
}

type InfoReq struct {
	g.Meta `path:"/roles/{id}" tags:"角色管理" method:"get" summary:"角色详情"`
	Id     int64 `query:"id" v:"required|min:1"`
}

type InfoRes struct {
	g.Meta      `mime:"application/json"`
	Id          int64             `json:"id"`
	AppCode     string            `json:"appCode"`
	Name        string            `json:"name"`
	Description string            `json:"description"`
	Permissions []Permission      `json:"permissions"`
	Menus       []entity.RoleMenu `json:"menus"`
	Users       []int64           `json:"users"`
}

type AssignUserReq struct {
	g.Meta  `path:"/roles/{id}/users" tags:"角色管理" method:"post" summary:"将用户分配给角色"`
	Id      int64   `query:"id" v:"required|min:1"`
	UsersId []int64 `json:"usersId"`
}
type AssignUserRes struct {
	Rows int `json:"rows"`
}
type AssignPermissionReq struct {
	g.Meta        `path:"/roles/{id}/permissions" tags:"角色管理" method:"post" summary:"将权限分配给角色"`
	Id            int64   `query:"id" v:"required|min:1"`
	MenuId        int64   `json:"menuId" v:"required|min:1"`
	Include       bool    `json:"include" v:"required" description:"是否包含子菜单"`
	PermissionsId []int64 `json:"permissionsId"`
}
type AssignPermissionRes struct {
	Rows int `json:"rows"`
}

type UnassignUserReq struct {
	g.Meta  `path:"/roles/{id}/users" tags:"角色管理" method:"delete" summary:"将用户从角色中移除"`
	Id      int64   `query:"id" v:"required|min:1"`
	UsersId []int64 `json:"usersId"`
}
type UnassignUserRes struct {
	Rows int `json:"rows"`
}
type UnassignPermissionReq struct {
	g.Meta        `path:"/roles/{id}/permissions" tags:"角色管理" method:"delete" summary:"将权限从角色中移除"`
	Id            int64   `query:"id" v:"required|min:1"`
	MenuId        int64   `json:"menuId" v:"required|min:1"`
	Include       bool    `json:"include" v:"required" description:"是否包含子菜单"`
	PermissionsId []int64 `json:"permissionsId"`
}
type UnassignPermissionRes struct {
	Rows int `json:"rows"`
}

type Permission struct {
	Id        int64  `json:"id"`
	Name      string `json:"name"`
	Path      string `json:"path"`
	Operation string `json:"operation"`
	MenuId    int64  `json:"menuId"`
}

type User struct {
	Username string `json:"username" description:"用户名"`
}

// input and output struct

type AssignUserInput struct {
	TenantCode string  `json:"tenantCode"`
	Id         int64   `json:"roleId"`
	UsersId    []int64 `json:"usersId"`
}
type AssignUserOutput struct {
	Rows int `json:"rows"`
}
type AssignPermissionInput struct {
	// TenantCode    string  `json:"tenantCode"`
	Id            int64   `json:"roleId"`
	MenuId        int64   `json:"menuId"`
	Include       bool    `json:"include" description:"是否包含子菜单"`
	PermissionsId []int64 `json:"permissionsId"`
}
type AssignPermissionOutput struct {
	Rows int `json:"rows"`
}
type UnassignUserInput struct {
	TenantCode string  `json:"tenantCode"`
	Id         int64   `json:"roleId"`
	UsersId    []int64 `json:"usersId"`
}
type UnassignUserOutput struct {
	Rows int `json:"rows"`
}
type UnassignPermissionInput struct {
	Id            int64   `json:"roleId"`
	MenuId        int64   `json:"menuId"`
	Include       bool    `json:"include" description:"是否包含子菜单"`
	PermissionsId []int64 `json:"permissionsId"`
}
type UnassignPermissionOutput struct {
	Rows int `json:"rows"`
}

type ListInput struct {
	AppCode string `json:"appCode"`
}
type ListOutput struct {
	Data []entity.UserRole `json:"data"`
}
type AddInput struct {
	do.UserRole
}
type AddOutput struct {
	Id int64 `json:"id"`
}
type UpdateInput struct {
	do.UserRole
}
type UpdateOutput struct {
	Rows int64 `json:"rows"`
}
type DeleteInput struct {
	Id int64 `json:"id"`
	// TenantCode string `json:"tenantCode"`
}
type DeleteOutput struct {
	Rows int64 `json:"rows"`
}
type InfoInput struct {
	Id int64 `json:"id"`
	// TenantCode string `json:"tenantCode"`
}
type InfoOutput struct {
	entity.UserRole `json:"role"`
	Permissions     []Permission      `json:"permissions"`
	Menus           []entity.RoleMenu `json:"menus"`
	Users           []int64           `json:"users"`
}
